'''
Created on 5 nov 2012

@author: Lanboost
'''
from CFilter import *
from CBufferedImage import *
import ImageLibr
import Image

class CFilterColor(CFilter):
    
    multir = 1
    multig = 1
    multib = 1
    
    def setVariables(self, att):
        if not att and len(att) != 3:
            return
        if att[0] >= 0 and att[0] <= 3:
            self.multir = att[0]
        if att[1] >= 0 and att[1] <= 3:
            self.multig = att[1]
        if att[2] >= 0 and att[2] <= 3:
            self.multib = att[2]
            
    def applyFilter(self, aImage):
        bufferedimage = CBufferedImage(aImage)
        
        for x in range(bufferedimage.getWidth()):
            for y in range(bufferedimage.getHeight()):
                pixel = bufferedimage.getPixel(x, y)
                r = pixel*self.multir
                if r > 255:
                    r = 255
                g = pixel*self.multig
                if g > 255:
                    g = 255
                b = pixel*self.multib
                if b > 255:
                    b = 255
                pixel = (r, g, b)
                bufferedimage.setPixel(x, y, pixel)
        
        return bufferedimage.convertToImage()
                
        
        